package main

import (
// 	"fmt"
	"os"
	"log"
	"io"
	"minimips"
)

func Instructions ()([]uint32){
	instr := make([]uint32,100)
	data := make([]byte, 4)
	count := 4;
	var err error;
	file, err := os.Open("spim.dump")
	if err != nil {
		log.Fatal(err)
	}

	for i:=0;count!=0;i++ {
		count, err = file.Read(data)
		if err != nil && err != io.EOF {
			log.Fatal(err)
		}
		//fmt.Printf("data: 0x%x\n",data)
		instr[i] = 0
		for j:=0;j<4;j++ {
			instr[i] += uint32(data[j]) << uint32(8*(3-j))
			//fmt.Printf("instrp: 0x%x\n",instr[i])
		}
		//fmt.Printf("instr: 0x%x\n",instr[i])
	}
	return instr
}

func main() {
	end := make(chan uint32)
	instructions := make(chan []uint32)
// 	inst := Instrutions()
// 	for i:=0;i<10;i++ {
// 		fmt.Printf("inst: 0x%x\n",inst[i])
// 	}

	go minimips.Minimips(instructions)
	instructions <- Instructions()
	
	for{
		<- end
	}
}